//
// Created by Bili_TianX_Computer on 2021/7/10.
//

#include "AddUserDialog.h"

AddUserDialog::AddUserDialog()
{
    editLayout = new QFormLayout();
    nameEdit = new QLineEdit();
    accountEdit = new QLineEdit();
    passwordEdit = new QLineEdit();
    adminButton = new QCheckBox();
    widgetLayout = new QVBoxLayout();
    box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);

    editLayout->addRow("姓名", nameEdit);
    editLayout->addRow("用户名", accountEdit);
    editLayout->addRow("密码", passwordEdit);
    editLayout->addRow("管理员", adminButton);
    widgetLayout->addLayout(editLayout);
    widgetLayout->addWidget(box);

    setWindowTitle("添加用户");
    setLayout(widgetLayout);

    box->button(QDialogButtonBox::Ok)->setText("确定");
    box->button(QDialogButtonBox::Cancel)->setText("取消");

    connect(box, SIGNAL(accepted()), this, SLOT(acceptedSlot()));
    connect(box, SIGNAL(rejected()), this, SLOT(rejectedSlot()));
}

void AddUserDialog::acceptedSlot()
{
    user = new User(nameEdit->text(),
                    accountEdit->text(),
                    passwordEdit->text(),
                    adminButton->isChecked());
    this->accept();
}

void AddUserDialog::rejectedSlot()
{
    this->reject();
}
